
global data_folder "W:\intimate\data"
global log_folder "W:\intimate\dofiles\logs"
global output_folder "W:\intimate\results_revision"

// Take sample of DV couples from final restriction and merge back in with crime data 
use "W:\intimate\data\allwomen_data_clean_withDV", clear 
keep if dv_couple==1

/* restrict to the same sample as matching */
merge 1:m shnro year_start_cohab using "W:\intimate\data\match_victim_data_clean_new", keepusing (shnro)
rename _merge merge_matched_dv  
keep if merge_matched_dv==3


g same_spouse0 = 1
forvalues i = 1/5 {
	g same_spouseB`i' = (sphnro0 == sphnroB`i')
}
forvalues i = 1/5 {
	g same_spouseF`i' = (sphnro0 == sphnroF`i')
}

local varlist ptoim1 tyotu same_spouse

forvalues i = 1/5 {
    local j = 6 -`i'
    foreach thing in `varlist' {
		ren `thing'B`i' `thing'`j'
	}
}

foreach thing in `varlist' {
    ren `thing'0 `thing'6
}

forvalues i = 1/5 {
    local j = 6 +`i'
    foreach thing in `varlist' {
		ren `thing'F`i' `thing'`j'
	}
}

g group_id = _n

reshape long `varlist', i(group_id) j(time)
keep `varlist' time dv_couple
collapse (mean) `varlist', by(time dv_couple)

graph twoway line ptoim1 time if dv_couple==1, lcolor(black) ///
		xlabel(1 "-5" 2 "-4" 3 "-3" 4 "-2" 5 "-1" 6 "0" 7 "1" 8 "2" 9 "3" 10 "4" 11 "5") ///
		xtitle("Time from Cohabitation") ytitle("Employment") ///
		graphregion(color(white)) ylabel(0.4(0.05)0.6) ///
		xline(6, lpattern(dash) lcolor(black))
graph export "$result_folder\victim_descrip_ptoim1.pdf", replace
	
graph twoway line tyotu time if dv_couple==1, lcolor(black) ///
		xlabel(1 "-5" 2 "-4" 3 "-3" 4 "-2" 5 "-1" 6 "0" 7 "1" 8 "2" 9 "3" 10 "4" 11 "5") ///
		xtitle("Time from Cohabitation") ytitle("Earnings") ///
		graphregion(color(white))  ///
		xline(6, lpattern(dash) lcolor(black)) ///
		ylabel(8000(2000)14000)
graph export "$result_folder\victim_descrip_tyotu.pdf", replace

graph twoway line tyotu time if dv_couple==1, lcolor(black) ///
		xlabel(1 "-5" 2 "-4" 3 "-3" 4 "-2" 5 "-1" 6 "0" 7 "1" 8 "2" 9 "3" 10 "4" 11 "5") ///
		xtitle("Time from Cohabitation") ytitle("Earnings") ///
		graphregion(color(white))  ///
		xline(6, lpattern(dash) lcolor(black)) ///
		ylabel(8000(4000)20000)
graph export "$result_folder\victim_descrip_tyotu_appendix.pdf", replace


